import os
import subprocess
import sys
from os.path import join
from shutil import rmtree, ignore_patterns, copytree,copy2

absPath = os.path.split(os.path.realpath(__file__))[0]

urlStr = "http://192.168.1.12/remote-assets/"


def run_shell(shell):
    pop = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=sys.stderr, close_fds=True, stdout=sys.stdout,
                           universal_newlines=True, shell=True, bufsize=1)
    pop.communicate()
    return pop.returncode


if __name__ == '__main__':
    cmd = r'call node version_generator.js -v {0} -u {1} -s ./build/windows/assets -d assets/'.format("1.1.1", urlStr)

    print(run_shell(cmd))

    rmtree('./remote-assets', True)
    print("删除旧资源文件夹End")

    ignore = ignore_patterns('.idea', '.vscode')

    copytree(join(absPath, r"build\windows\assets"), join(absPath, "remote-assets"), symlinks=True, ignore=ignore)

    copy2('./assets/project.manifest', './remote-assets')
    copy2('./assets/version.manifest', './remote-assets')
